<template>
    <div>
       房型名称: <select v-model="info.lid">
            <option value="">请选择</option>
            <option :value="item.nid" v-for="item in level" :key="item.nid">{{item.oname}}</option>  
        </select>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房型名称</td>
                    <td>单价</td>
                    <td>室内面积</td>
                    <td>最多入住人数</td>
                    <td>图片</td>
                    <td>房型描述</td>
                    <td>是否有窗</td>
                    <td>操作</td>
                </tr>
                <tr v-for="value in infoo.list">
                    <td>{{value.oname}}</td>
                    <td>{{value.prcie}}</td>
                    <td>{{value.area}}</td>
                    <td>{{value.people}}</td>
                    <td>{{value.img}}</td>
                    <td>{{value.describe}}</td>
                    <td>{{value.iswin}}</td>
                    <td></td>
                </tr>
            </tbody>
        </table>
    </div>
    <div>
        <span>总条数:{{infoo.totalnum}}</span>
        <span>总页数:{{infoo.totalpage}}</span>
        <span>当前页:{{info.pageindex}}/{{infoo.totalpage}}</span>
        <input type="button" value="首页" @click="fn(1)">
        <input type="button" value="上一页" @click="fn(info.pageindex-1)">
        <input type="button" v-for="o in infoo.totalpage" :value="o" @click="fn(o)">
        <input type="button" value="下一页" @click="fn(info.pageindex+1)">
        <input type="button" value="尾页" @click="fn(infoo.totalpage)">
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import {ref,onMounted} from 'vue'

let info:any=ref({
    lid:"",
    pageindex:1,
    pagesize:2
})

let infoo:any=ref({
    list:[],
    totalnum:"",
    totalpage:""
})
let level:any=ref([])
onMounted(()=>{
    GetList();
    Getlevel();
})
const fn=(num:any)=>{
    if(num<1){
        info.value.pageindex=1;
        return;
    }
    if(num>infoo.value.totalpage){
        info.value.pageindex=infoo.value.totalpage
        return;
    }
    info.value.pageindex=num;
    GetList()
}

const Getlevel=()=>{
    axios({
        url:'https://localhost:7058/api/Ht/HtLevel',
        method:"get",
    })
    .then((res)=>{
        console.log(res);
    })
    .catch((err)=>{
        console.log(err);
    })
}
const GetList=()=>{
    axios({
        url:'https://localhost:7058/api/Ht/GetHt',
        method:'get',
        params:info.value
    })
    .then((res)=>{
        console.log(res);
        infoo.value=res.data
    })
    .catch((err)=>{
        console.log(err);
    })
}
</script>

<style scoped>

</style>